import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { RolePermission } from './RolePermission';

@Entity('permission', { schema: 'blog_back' })
export class Permission {
  @PrimaryGeneratedColumn({
    type: 'int',
    name: 'id',
    comment: '主键id',
    unsigned: true,
  })
  id: number;

  @Column('varchar', {
    name: 'id_path',
    nullable: true,
    comment: '节点路径',
    length: 255,
  })
  idPath: string | null;

  @Column('enum', {
    name: 'type',
    comment: '节点归属类型',
    enum: ['1'],
    default: () => "'1'",
  })
  type: '1';

  @Column('varchar', { name: 'name', comment: '权限名称', length: 64 })
  name: string;

  @Column('varchar', { name: 'zn_name', comment: '权限中文中文', length: 64 })
  znName: string;

  @Column('enum', {
    name: 'func_type',
    comment: '菜单还是按钮',
    enum: ['1', '2'],
  })
  funcType: '1' | '2';

  @Column('varchar', {
    name: 'page_url',
    nullable: true,
    comment: '页面节点的路径',
    length: 255,
  })
  pageUrl: string | null;

  @Column('json', { name: 'api_list', comment: '节点的接口校验' })
  apiList: object;

  @Column('timestamp', {
    name: 'create_time',
    comment: '创建时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createTime: Date;

  @Column('timestamp', {
    name: 'update_time',
    comment: '更新时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  updateTime: Date;

  @OneToMany(
    () => RolePermission,
    (rolePermission) => rolePermission.permission,
  )
  rolePermissions: RolePermission[];
}
